GetBookmark Method Example

This example checks the updated value of a particular column to make sure that the new value lies between the values of the previous and the next rows.

Sub DataGrid1_BeforeColUpdate (ColIndex As Integer, _
 OldValue as Variant, PrevVal, NextVal, CurVal, Cancel As Integer)
   If ColIndex = 1 Then
      PrevVal = DataGrid1.Columns(1).CellValue(_
       DataGrid1.GetBookmark(-1))
      NextVal = DataGrid1.Columns(1).CellValue(_
       DataGrid1.GetBookmark(1))
      CurVal = DataGrid1.Columns(1).Value
      If CurVal > PrevVal Or CurVal < NextVal  Then
         Cancel = True
         MsgBox "Value must be between" & PrevVal _
          & " and " & NextVal
      End If
   End If
End Sub